//
//  SourcesOrderListCell.m
//  HuoFeiDaShipper
//
//  Created by mac on 2019/11/30.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "SourcesOrderListCell.h"
#import "HCSStarRatingView.h"
#import "UIImage+HDExtension.h"

@interface SourcesOrderListCell()
@property (strong, nonatomic) CJLabel *labOrderNum;
//@property (strong, nonatomic) CJLabel *labOrderStatue;
@property (nonatomic,strong) CJLabel *labDriverName;
@property (nonatomic,strong) CJLabel *labStarNum;
@property (nonatomic,strong) CJLabel *labHistoryOrderNums;
@property (nonatomic,strong) CJLabel *labPrice; // 成交单价
@property (nonatomic,strong) CJLabel *labCarLicense; // 车牌
@property (nonatomic,strong) CJLabel *labWeight; // 承运数量
@property (nonatomic,strong) CJLabel *SJPriceLabel;//司机应收
@property (nonatomic,strong) CJLabel *XHTimeLabel;//卸货时间
@property (nonatomic,strong) CJLabel *SJPriceLabelView;//司机应收
@property (nonatomic,strong) CJLabel *XHTimeLabelView;//卸货时间
@property (strong, nonatomic) UIView *viewDetail;
@property (nonatomic,strong) HCSStarRatingView *viewRate;
@property (nonatomic,strong) CJView *viewStar;
@property (nonatomic,strong) CJLabel *labOrderStatue;
@property (nonatomic,strong) UIImageView *imgVDriver;

@property (nonatomic,strong) FlexTouchView *touchCancle; // 取消
@property (nonatomic,strong) FlexTouchView *touchCancleSure; // 取消确认
//@property (nonatomic,strong) FlexTouchView *touchLoadGoods;
@property (nonatomic,strong) FlexTouchView *touchYuFu; // 预付

@property (nonatomic,strong) FlexTouchView *touchLoadGoodsSure;
@property (nonatomic,strong) FlexTouchView *touchAgainLoadGoods; //重新装货
//@property (nonatomic,strong) FlexTouchView *touchUnloadGoods; // 卸货
@property (nonatomic,strong) FlexTouchView *touchUnloadGoodsSure; // 卸货queren
@property (nonatomic,strong) FlexTouchView *touchAgainUnloadGoods; // 重新
@property (nonatomic,strong) FlexTouchView *touchAccountPrice; //核算
@property (nonatomic,strong) FlexTouchView *touchOpenInvoice; // 开票
@property (nonatomic,strong) FlexTouchView *touchApplyRemit; // 货主打款
@property (nonatomic,strong) FlexTouchView *touchEvaluate; // 评价
@property (nonatomic,strong) FlexTouchView *touchSeeEvaluate;
@property (nonatomic,strong) FlexTouchView *touchAdjustOrder; // 调单
@property (nonatomic,strong) FlexTouchView *touchComplaint; // 投诉
@property (nonatomic,strong) FlexTouchView *touchComplaintRecord; // 投诉记录
@property (nonatomic,strong) FlexTouchView *touchTurnDown; //驳回

@property (nonatomic,strong) FlexTouchView *touchTurnDown1; //驳回
@property (nonatomic,strong) FlexTouchView *touchCancle1; // 取消
@property (nonatomic,strong) FlexTouchView *touchCancleSure1; // 取消确认
//@property (nonatomic,strong) FlexTouchView *touchLoadGoods1;
@property (nonatomic,strong) FlexTouchView *touchYuFu1; // 预付

@property (nonatomic,strong) FlexTouchView *touchLoadGoodsSure1;
@property (nonatomic,strong) FlexTouchView *touchAgainLoadGoods1; //重新装货
//@property (nonatomic,strong) FlexTouchView *touchUnloadGoods1; // 卸货
@property (nonatomic,strong) FlexTouchView *touchUnloadGoodsSure1; // 卸货queren
@property (nonatomic,strong) FlexTouchView *touchAgainUnloadGoods1; // 重新
@property (nonatomic,strong) FlexTouchView *touchAccountPrice1; //核算
@property (nonatomic,strong) FlexTouchView *touchOpenInvoice1; // 开票
@property (nonatomic,strong) FlexTouchView *touchApplyRemit1; // 货主打款
@property (nonatomic,strong) FlexTouchView *touchEvaluate1; // 评价
@property (nonatomic,strong) FlexTouchView *touchSeeEvaluate1;
@property (nonatomic,strong) FlexTouchView *touchAdjustOrder1; // 调单
@property (nonatomic,strong) FlexTouchView *touchComplaint1; // 投诉
@property (nonatomic,strong) FlexTouchView *touchComplaintRecord1; // 投诉记录
//@property (nonatomic,strong) CJView *viewSendsOrders; //
//@property (nonatomic,strong) CJView *viewAbnormalUpLoad; // 异常上报
@property (nonatomic,strong) FlexScrollView *scrollViewOrderList;
@property (nonatomic,strong) UIView *viewBottom;
@end

@implementation SourcesOrderListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setCellInfoWithModel:(SourcesOrderListModel *)model Index:(NSString *)index{
    self.labOrderNum.text = model.orderCode;
//    self.labOrderStatue.text = @"状态啊";
//    self.labOrderStatue.textColor = [UIColor cjMainColorText];
//    model.driverHeadImg
//    [self.imgVDriver sd_setImageWithURL:[NSURL URLWithString:[CJControl getThreeUnaryValueStr:model.driverHeadImg]] placeholderImage:[UIImage imageNamed:@"zcj_default_person_icon"]];
    
    if ([CJRegular getIsStrEmpty:[CJControl getThreeUnaryValueStr:model.driverHeadImg]]) {
        
    }else{
        self.imgVDriver.image = [UIImage hd_captureCircleImageWithURL:[CJControl getThreeUnaryValueStr:model.driverHeadImg] andBorderWith:0 andBorderColor:[UIColor cjClearColor]];
    }
    
    if (model.isCancel == 0) {
        
        switch (model.status) {
            case 1:
                self.labOrderStatue.text = @"已接单";
                break;
            case 2:
                self.labOrderStatue.text = @"已装货";
                break;
            case 3:
                self.labOrderStatue.text = @"已卸货";
                break;
            case 4:
                self.labOrderStatue.text = @"已核算";
                break;
            case 5:
                self.labOrderStatue.text = @"已完成";
                break;
            case 6:
                self.labOrderStatue.text = @"待审核";
                break;
                
            default:
                break;
        }
        
    }else{
        self.labOrderStatue.text = @"已撤销";
    }
    
    self.labDriverName.text = model.driverName;
    
    if ([CJRegular getIsStrEmpty:model.driverName]) {
        self.labDriverName.hidden = YES;
    }else{
        self.labDriverName.hidden = NO;
    }

    [self.viewStar addSubview:self.viewRate];
    self.viewRate.value = model.driverAverage;
    self.labStarNum.text = CJStringWithFormat(@"%0.1f",model.driverAverage);
    self.labHistoryOrderNums.text = CJStringWithFormat(@"历史订单:%ld单",(long)model.driverHistoryCount);
    self.labCarLicense.text = model.vehicleLicense;
    
    self.labWeight.text = CJStringWithFormat(@"%@%@",@(model.loadWeight).cj_description,model.coalUnitName);
    self.labPrice.text = CJStringWithFormat(@"%@%@",@(model.unloadWeight).cj_description,model.coalUnitName);
    self.SJPriceLabel.text = CJStringWithFormat(@"%@",@(model.deliveryCashFee).cj_money_description);
    if (model.status < 3) {
        self.SJPriceLabelView.hidden = YES;
    }else{
        self.SJPriceLabelView.hidden = NO;
    }
    if ([CJRegular getIsStrEmpty:model.signTime]) {
        self.XHTimeLabelView.hidden = YES;
    }else{
        self.XHTimeLabelView.hidden = NO;
    }
    self.XHTimeLabel.text = CJStringWithFormat(@"%@",model.signTime);
//    self.labPrice.text = CJStringWithFormat(@"%@%@",@(model.taxPrice).cj_money_description,model.isTrunkName);
//    self.labWeight.text = CJStringWithFormat(@"%@%@",@(model.loadQuantity).cj_description,model.coalUnitName); //coalUnitName
    // weight
//
    // 判断逻辑
    NSString *secondUploadDetail = [CJControl getSecondUploadDetail];

    self.touchCancle.hidden = model.status == 1 && model.isCancel == 0 ? NO:YES;
    self.touchCancleSure.hidden = model.status == 1 && model.isCancel == 1  && model.cancelType == 0? NO:YES;
    self.touchYuFu.hidden  = model.status >1 && model.status < 4 && model.isLoadingConfirm == 1 && model.isMonthlyOrder == 0 && model.isUnloadingConfirm == 0 ? NO:YES;
    //    self.touchLoadGoods.hidden = model.isCancel != 1 && model.status == 1 && ![model.driverCode isEqualToString:@""]  ? NO:YES;
    //    self.touchUnloadGoods.hidden = model.status == 2 && (model.isShipperLoadingConfirm == 0 ||(model.isShipperLoadingConfirm == 1 && model.isLoadingConfirm == 1)) ? NO:YES;
    //     self.touchUnloadGoods.hidden = model.status == 2  && model.isLoadingConfirm == 1 ? NO:YES;
    self.touchLoadGoodsSure.hidden = model.status == 2  && model.isLoadingConfirm == 0 ? NO:YES;
    self.touchUnloadGoodsSure.hidden = model.status == 3 && model.isUnloadingConfirm == 0 ? NO:YES;

    self.touchAgainLoadGoods.hidden = (model.status == 2 || model.status == 3) && secondUploadDetail.intValue == 1 ? NO:YES;

    self.touchAgainUnloadGoods.hidden = model.status == 3 && secondUploadDetail.intValue == 1 ? NO:YES;

    //    self.touchAccountPrice.hidden = model.status == 3 && (model.isShipperUnloadingConfirm == 0 || (model.isShipperUnloadingConfirm == 1 && model.isUnloadingConfirm ==1))&&[CJControl getIsIndependentCheckout] ? NO:YES;
    self.touchAccountPrice.hidden = model.status == 3 && model.isUnloadingConfirm ==1 && [CJControl getIsIndependentCheckout] == 1 && [CJControl getIsHideAcccountPrice] == NO && index.intValue != 10 ? NO:YES;
    //    && model.isIndependentCheckout == 1
    self.touchOpenInvoice.hidden = model.status == 5 && model.invoiceStatus == 0 ? NO:YES;
    self.touchApplyRemit.hidden = model.status == 4 && (model.applyStatus == 0 || model.applyStatus == 2)  && [CJControl getIsHideApplyRemit] == NO ? NO:YES;

    self.touchEvaluate.hidden = (model.status == 3 || model.status == 4 || model.status == 5) && model.isShipmentComment == 0 ? NO:YES;
    self.touchSeeEvaluate.hidden = (model.status == 3 || model.status == 4 || model.status == 5) && model.isShipmentComment == 1 ? NO:YES;
    self.touchComplaint.hidden = model.status == 1 ||model.status == 2 ||model.status == 3 ||model.status == 4 ||model.status == 6 ? NO:YES;
    self.touchComplaintRecord.hidden = model.status == 1 ||model.status == 2 ||model.status == 3 ||model.status == 4 ||model.status == 5 ||model.status == 6 ? NO:YES;
    self.touchAdjustOrder.hidden = (model.status == 1 || model.status == 2) && model.isCancel != 1 ? NO:YES;
    self.touchTurnDown.hidden = model.status==4 && model.isSettle == 1 && model.applyStatus != 1 ? NO:YES;

    self.touchCancle1.hidden = model.status == 1 && model.isCancel == 0 ? NO:YES;
    self.touchCancleSure1.hidden = model.status == 1 && model.isCancel == 1 && model.cancelType == 0 ? NO:YES;
    self.touchYuFu1.hidden  = model.status >1 && model.status < 4 && model.isLoadingConfirm == 1 && model.isMonthlyOrder == 0 && model.isUnloadingConfirm == 0 ? NO:YES;
    //         self.touchLoadGoods1.hidden = model.isCancel != 1 && model.status == 1 && ![model.driverCode isEqualToString:@""]  ? NO:YES;
    //    self.touchUnloadGoods.hidden = model.status == 2 && (model.isShipperLoadingConfirm == 0 ||(model.isShipperLoadingConfirm == 1 && model.isLoadingConfirm == 1)) ? NO:YES;
    //          self.touchUnloadGoods1.hidden = model.status == 2  && model.isLoadingConfirm == 1 ? NO:YES;
    self.touchLoadGoodsSure1.hidden = model.status == 2  && model.isLoadingConfirm == 0 ? NO:YES;
    self.touchUnloadGoodsSure1.hidden = model.status == 3 && model.isUnloadingConfirm == 0 ? NO:YES;

    self.touchAgainLoadGoods1.hidden = (model.status == 2 || model.status == 3) && secondUploadDetail.intValue == 1 ? NO:YES;

    self.touchAgainUnloadGoods1.hidden = model.status == 3 && secondUploadDetail.intValue == 1 ? NO:YES;

    //    self.touchAccountPrice.hidden = model.status == 3 && (model.isShipperUnloadingConfirm == 0 || (model.isShipperUnloadingConfirm == 1 && model.isUnloadingConfirm ==1))&&[CJControl getIsIndependentCheckout] ? NO:YES;
    self.touchAccountPrice1.hidden = model.status == 3 && model.isUnloadingConfirm ==1 &&[CJControl getIsIndependentCheckout] == 1 &&[CJControl getIsHideAcccountPrice] == NO && index.intValue != 10 ? NO:YES;
    //    && model.isIndependentCheckout == 1
    self.touchOpenInvoice1.hidden = model.status == 5 && model.invoiceStatus == 0 ? NO:YES;
    self.touchApplyRemit1.hidden = model.status == 4 && (model.applyStatus == 0 || model.applyStatus == 2)  && [CJControl getIsHideApplyRemit] == NO ? NO:YES;

    self.touchEvaluate1.hidden = (model.status == 3 || model.status == 4 || model.status == 5 || model.status == 6) && model.isShipmentComment == 0 ? NO:YES;
    self.touchSeeEvaluate1.hidden = (model.status == 3 || model.status == 4 || model.status == 5) && model.isShipmentComment == 1 ? NO:YES;
    self.touchComplaint1.hidden = model.status == 1 ||model.status == 2 ||model.status == 3 ||model.status == 4 ||model.status == 6 ? NO:YES;
    self.touchComplaintRecord1.hidden = model.status == 1 ||model.status == 2 ||model.status == 3 ||model.status == 4 ||model.status == 5 ||model.status == 6 ? NO:YES;
    self.touchAdjustOrder1.hidden = (model.status == 1 || model.status == 2) && model.isCancel != 1 ? NO:YES;
    self.touchTurnDown1.hidden = model.status==4 && model.isSettle == 1 && model.applyStatus != 1 ? NO:YES;
    
//    隐藏调单
    self.touchAdjustOrder.hidden = YES;
    self.touchAdjustOrder1.hidden = YES;
    
//    // 判断
    int i = 0;

    if (self.touchCancle.hidden == NO){
        i++;
    }
    if (self.touchCancleSure.hidden == NO){
        i++;
    }
//    if (self.touchLoadGoods.hidden == NO){
//        i++;
//    }
    if (self.touchYuFu.hidden == NO) {
        i++;
    }
    if (self.touchLoadGoodsSure.hidden == NO){
        i++;
    }
    if (self.touchAgainLoadGoods.hidden == NO){
        i++;
    }
//    if (self.touchUnloadGoods.hidden == NO){
//        i++;
//    }
    if (self.touchUnloadGoodsSure.hidden == NO){
        i++;
    }
    if (self.touchAgainUnloadGoods.hidden == NO){
        i++;
    }
    if (self.touchAccountPrice.hidden == NO){
        i++;
    }
    if (self.touchOpenInvoice.hidden == NO){
        i++;
    }
    if (self.touchApplyRemit.hidden == NO){
        i++;
    }
    if (self.touchEvaluate.hidden == NO){
        i++;
    }
    if (self.touchSeeEvaluate.hidden == NO){
        i++;
    }
    if (self.touchAdjustOrder.hidden == NO){
        i++;
    }
    if (self.touchComplaint.hidden == NO){
        i++;
    }
    if (self.touchComplaintRecord.hidden == NO){
        i++;
    }
    
    if (self.touchTurnDown.hidden == NO){
        i++;
    }
    
//    DLog(@"============ %d",i);

    if (i > 4) {
          self.scrollViewOrderList.hidden = NO;
          self.viewBottom.hidden = YES;
      }else{
          self.scrollViewOrderList.hidden = YES;
          self.viewBottom.hidden = NO;
      }
}

- (void)btnClickPhoneAction{
    
    if (self.blockClickPhone) {
        self.blockClickPhone(@"");
    }
}

- (HCSStarRatingView *)viewRate{
    if (!_viewRate) {
      _viewRate =   [[HCSStarRatingView alloc]initWithFrame:CGRectMake(0,0,110,30)];
        _viewRate.tintColor = [UIColor cjStarRateColor];
        _viewRate.starBorderColor = [UIColor cjClearColor];
        _viewRate.emptyStarColor = [UIColor cjEmptyStarRateColor];
        _viewRate.backgroundColor = [UIColor cjClearColor];
        _viewRate.enabled = NO;
        _viewRate.maximumValue = 5;
        _viewRate.allowsHalfStars = YES;
        _viewRate.minimumValue = 0;
    }
    return  _viewRate;
}

- (void)btnTouchCancleAction{
//    [CJAlert showStringDismissWithDelay:@"取消"];
    if (self.blockCancle) {
        self.blockCancle(@"");
    }
}

- (void)btnTouchCancleSureAction{
//    [CJAlert showStringDismissWithDelay:@"取消确认"];
    if (self.blockCancleSure) {
        self.blockCancleSure(@"");
    }
}
- (void)btnTouchYuFuAction{
//    预付
    if (self.blockYuFu) {
        self.blockYuFu(@"");
    }
}

- (void)btnTouchLoadGoodsAction{
//    [CJAlert showStringDismissWithDelay:@"装货"];
    if (self.blockLoadGoods) {
        self.blockLoadGoods(@"");
    }
}
// touchLoadGoodsSure
- (void)btnTouchLoadGoodsSureAction{
//    [CJAlert showStringDismissWithDelay:@"装货确认"];
    if (self.blockLoadGoodsSure) {
        self.blockLoadGoodsSure(@"");
    }
}
- (void)btnTouchAgainLoadGoodsAction{
//    [CJAlert showStringDismissWithDelay:@"重新装货"];
    if (self.blockAgainLoadGoods) {
        self.blockAgainLoadGoods(@"");
    }
}

- (void)btnTouchUnloadGoodsAction{
//    [CJAlert showStringDismissWithDelay:@"卸货"];
    if (self.blockUnloadGoods) {
        self.blockUnloadGoods(@"");
    }
}

- (void)btnTouchUnloadGoodsSureAction{
//    [CJAlert showStringDismissWithDelay:@"卸货确认"];
    if (self.blockUnloadGoodsSure) {
        self.blockUnloadGoodsSure(@"");
    }
}

- (void)btntouchAgainUnloadGoodsAction{
//    [CJAlert showStringDismissWithDelay:@"重新卸货"];
    if (self.blockAgainUnloadGoods) {
        self.blockAgainUnloadGoods(@"");
    }
}

- (void)btnAouchAccountPriceAction{
//    [CJAlert showStringDismissWithDelay:@"核算"];
    if (self.blockAccountPrice) {
        self.blockAccountPrice(@"");
    }
}

- (void)btnTouchOpenInvoice{
//    [CJAlert showStringDismissWithDelay:@"开票"];
    if (self.blockOpenInvoice) {
        self.blockOpenInvoice(@"");
    }
}

- (void)btnTouchApplyRemitAction{
//    [CJAlert showStringDismissWithDelay:@"货主打款"];
    if (self.blockApplyRemit) {
        self.blockApplyRemit(@"");
    }
}
- (void)btnTouchEvaluateAction{
//    [CJAlert showStringDismissWithDelay:@"评价"];
    if (self.blockEvaluate) {
        self.blockEvaluate(@"");
    }

}

// touchSeeEvaluate
- (void)btnTouchSeeEvaluateAction{
    if (self.blockSeeEvaluate) {
        self.blockSeeEvaluate(@"");
    }
}

- (void)btnTouchAdjustOrderAction{
//    [CJAlert showStringDismissWithDelay:@"调单"];
    if (self.blockAdjustOrder) {
        self.blockAdjustOrder(@"");
    }
}
/// 投诉
- (void)btnTouchComplaintAcion{
    if (self.blockComplaint) {
        self.blockComplaint(@"");
    }
}

- (void)btnTouchComplaintRecordAction{
//    [CJAlert showStringDismissWithDelay:@"投诉记录"];
    if (self.blockComplaintRecord) {
        self.blockComplaintRecord(@"");
    }
}

/// 驳回
- (void)btnTouchTurnDownAction{
    
    if (self.blcokTurnDown) {
        self.blcokTurnDown(@"");
    }
}
///备注
- (void)remarkTouchComplaintAcion{
    if (self.blcokRemarkTurnDown) {
        self.blcokRemarkTurnDown(@"");
    }
}
//
//- (void)btnComplaintDriverAction{
//    [CJAlert showStringDismissWithDelay:@"投诉司机"];
//}
//
//- (void)btnSendsOrdersAction{
//    [CJAlert showStringDismissWithDelay:@"派单"];
//}
//
//
//
//- (void)btnAbnormalUpLoadAction{
//    [CJAlert showStringDismissWithDelay:@""];
//}
//


@end

